package vn.aptech.scrumgroup.util;

import android.graphics.Paint;
import demo.axitdn.physic.Unit;

public class DrawUtil {
	public static float calculateTextSize(String text, float width, Paint p,
			int numOfLoop) {
		// Log.d("text size", String.valueOf(p.getTextSize()));
		// Log.d("width", String.valueOf(width));
		float size = 0;
		for (int i = 0; i < numOfLoop; i++) {
			size = p.getTextSize();
			float currentWidth = p.measureText(text);
			// Log.d("current width", String.valueOf(currentWidth));
			size = size * width / currentWidth;
			p.setTextSize(size);
		}
		// Log.d("text size", String.valueOf(size));
		return size;
	}// end

	public static float calculateTextSize(String[] texts, float width, Paint p,
			int numOfLoop) {
		if (texts.length > 0) {
			float[] sizes = new float[texts.length];
			for (int i = 0; i < texts.length; i++) {
				sizes[i] = calculateTextSize(texts[i], width, p, numOfLoop);
			}
			float size = sizes[0];
			for(int i = 1; i < sizes.length; i++){
				if(size > sizes[i]){
					size = sizes[i];
				}
			}
			return size;
		}
		return p.getTextSize();
	}

	public static void calculateUnit(int screenWidth, int screenHeight) {
		MenuUtil.WINDOW_WIDTH = screenWidth;
		MenuUtil.WINDOW_HEIGHT = screenHeight;
		if (screenWidth > screenHeight) {
			Unit.i = screenHeight / 350f;
			Unit.j = screenWidth / 500f;
		} else {
			Unit.i = screenWidth / 350f;
			Unit.j = screenHeight / 500f;
		}
	}
}
